package com.redis.data.seckillshopping.controller;

import com.redis.data.seckillshopping.common.Result;
import com.redis.data.seckillshopping.entity.Consumer;
import com.redis.data.seckillshopping.enums.Operation;
import com.redis.data.seckillshopping.service.ConsumerService;
import com.redis.data.seckillshopping.utils.RedisUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 哲思小辉
 * @version 1.0.0
 * @ClassName ConsumerController.java
 * @Description 顾客控制类
 * @Param
 * @createTime 2020年03月25日 20:35:00
 */
@Component
@RestController
@RequestMapping("consumer")
@Api(value = "顾客控制类", tags = "顾客控制类")
public class ConsumerController {
    /**
     * 服务对象
     */
    @Autowired
    private ConsumerService consumerService;


    @PostMapping("addConsumer")
    @ApiOperation(value = "新增顾客", notes = "新增顾客")
    public Result<Consumer> addConsumer(@RequestBody Consumer consumer) {
        System.out.println("GOODS枚举里面获取数据：" + Operation.GOODS.getId(1));
        System.out.println("CONSUMER枚举里面获取数据：" + Operation.CONSUMER.getId(1));
        System.out.println("GOODSORDER枚举里面获取数据：" + Operation.GOODSORDER.getId(1));
        Consumer insert = this.consumerService.insert(consumer);
        RedisUtil.set(consumer.getId(), consumer);
        return Result.success(consumer);
    }

    @PostMapping("getConsumer")
    @ApiOperation(value = "获取顾客", notes = "获取顾客")
    public Result<Consumer> getConsumer(Integer consumerId) {
        Object o = RedisUtil.get(consumerId);
        System.out.println(o.getClass().getName());
        return Result.success(o);
    }


}